import Router from 'koa-router'
import { Models } from '../../../../common/typings/model'
import svgCaptcha from 'svg-captcha'
import Upload from '../../../../middlewares/upload'
import Auth from '../../../../middlewares/Auth'
import httpErrors from '../../../../core/HttpException'
import Config from '../../../../config/Config'

const router = new Router({
  prefix: `${Config.api_prefix}system/upload`,
})

const resourcePath = '/resource/uploads'

/*
 * 上传图片
 */
router.post('/img', Auth.verifyToken, Upload.single('img'), async (ctx: Models.Ctx, next) => {
  const { file } = ctx.req as {
    [prop: string]: any
  }
  // ctx.body = captcha.data;
  throw new httpErrors.Success({
    path: `${resourcePath}/${file.filename}`,
    name: file.filenam,
    mimetype: file.mimetype,
    size: file.size,
  })
})

export default router
